package com.suineg.pms.commons.wabacus;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.suineg.pms.commons.AppConfig;
import com.suineg.pms.entity.base.HouseOwner;
import com.suineg.pms.service.base.HouseOwnerService;
import com.wabacus.config.component.application.report.ReportBean;
import com.wabacus.system.ReportRequest;
import com.wabacus.system.component.application.report.configbean.editablereport.AbsEditActionBean;
import com.wabacus.system.component.application.report.configbean.editablereport.AbsEditableReportEditDataBean;
import com.wabacus.system.intercept.AbsInterceptorDefaultAdapter;
import com.wabacus.util.Consts;

/**
 * 业主管理 保存拦截器.
 *@author Suine
 */
public class OwnerInterceper extends AbsInterceptorDefaultAdapter{
	/** 日志输出对象 */
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	private HouseOwnerService houseOwnerService = AppConfig.getInstance().getWac().getBean(HouseOwnerService.class);

	@Override
	public int doSavePerAction(ReportRequest rrequest, ReportBean rbean, Map<String, String> mRowData, Map<String, String> mParamValues, AbsEditActionBean actionbean,
			AbsEditableReportEditDataBean editbean) {
		String idNo = mRowData.get("id_no");
		String id = mRowData.get("id");
		HouseOwner houseOwner = null;
		if(id != null){				//
			houseOwner = houseOwnerService.get(Long.valueOf(id));
			if(!idNo.equals(houseOwner.getIdNo())){
				check(rrequest,idNo);
			}
		}else{
			check(rrequest,idNo);
		}
		return super.doSavePerAction(rrequest, rbean, mRowData, mParamValues, actionbean, editbean);
	}
	
	public void check(ReportRequest rrequest,String idno){
		HouseOwner houseOwner = null;
		
		houseOwner = houseOwnerService.findByIdNo(idno);
		if(houseOwner != null){
			rrequest.getWResponse().getMessageCollector().warn("此‘证件号码’已经存在!", false, Consts.STATECODE_FAILED);
		}
	}
}

